//返回按钮创建与特效实现
$(function () {
	$("body").append("<span class='rocket' id='backTop'><img src='imgs/Top.png' alt=''/></span>");
	$("#backTop").css({"position":"fixed","right":"50px","bottom":"150px","display":"none"});

	var $back = $("#backTop");
	var topTarget = 0;
	var begBottom = parseFloat($back.css("bottom"));
	var endBottom = -100 + "px";

	//alert($(document).scrollTop());
	function toButtom(){
		//滚动窗口时显示隐藏火箭图标
		if ($(window).scrollTop() > 100) {
			$back.css("display","block");
			//火箭图标位置缓慢滚动到初始位置begBottom
			$back.stop().animate({"bottom": begBottom}, 600);
		} else {
			$back.css("display","none");
			//重置火箭图标位置到页面下
			$back.stop().css("bottom",endBottom);

		}
	}

	//页面滚动
	$(window).on("scroll",toButtom);

	topTarget = $(window).height();
	//改变窗口时重新获得火箭移动距离
	$(window).resize(function () {
		topTarget = $(window).height();
	});
	//alert($("html").width());

	//点击返回火箭图标
	$back.on("click", function () {
		//清除窗口滚动事件 阻止点击事件发生时 两个animate运动函数冲突
		$(window).off("scroll",toButtom);
		$back.stop().animate({"bottom":topTarget},600, function () {
			$(window).on("scroll",toButtom);
		});
		//页面到达顶部
		$("body").stop().animate({"scrollTop":0},1000);
	});


});